Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: derive some common traits on some UI types #12532

Merged
merged 1 commit into from
Mar 18, 2024

Conversation

awwsmm
Copy link
Contributor

@awwsmm awwsmm commented Mar 17, 2024

Objective

  • working with UI components in Bevy, I found myself wanting some of these common traits, like PartialEq for comparing simple types

Solution

  • I added only (hopefully) uncontroversial derives for some common UI types

Note that many types, unfortunately, can't have PartialEq derived for them, because they contain f32s and / or Vecs.

Comment on lines -21 to -29
impl Default for Text {
fn default() -> Self {
Self {
sections: Default::default(),
justify: JustifyText::Left,
linebreak_behavior: BreakLineOn::WordBoundary,
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BreakLineOn::WordBoundary is now the Default value, so impl Default for Text can be derived automatically

@@ -1796,7 +1796,7 @@ pub struct CalculatedClip {
/// `ZIndex::Local(n)` and `ZIndex::Global(n)` for root nodes.
///
/// Nodes without this component will be treated as if they had a value of `ZIndex::Local(0)`.
#[derive(Component, Copy, Clone, Debug, Reflect)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZIndex can impl Eq because its variants are just newtypes around i32s

@@ -4,6 +4,6 @@ use bevy_reflect::std_traits::ReflectDefault;
use bevy_reflect::Reflect;

/// Marker struct for buttons
#[derive(Component, Debug, Default, Clone, Copy, Reflect)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marker components can trivially impl many traits

@NthTensor NthTensor added A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A simple quality-of-life change that makes Bevy easier to use labels Mar 17, 2024
@james7132 james7132 added this to the 0.14 milestone Mar 18, 2024
@james7132 james7132 added this pull request to the merge queue Mar 18, 2024
Merged via the queue into bevyengine:main with commit fc4716f Mar 18, 2024
28 checks passed
@awwsmm awwsmm deleted the derive-common-traits-on-ui-types branch March 18, 2024 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A simple quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants